package com.hefei.oss.controller;

import com.hefei.common.utils.R;
import com.hefei.oss.serivce.IOssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author caizhengjun
 * @date 2021/3/5 下午5:39
 */
@RestController
@RequestMapping("/oss")
public class OssController {

    @Autowired
    private IOssService ossService;

    @PostMapping("/upload")
    public R upload(MultipartFile file) {

        String fileUrl = this.ossService.upload(file);
        if (!StringUtils.isEmpty(fileUrl)) {
            return R.ok().message("文件上传成功！").data(fileUrl);
        } else {
            return R.fail().message("文件上传失败！");
        }
    }
}
